package demo02;
//颜色划分
class Solution {
    public void sortColors(int[] nums) {
        int left = -1;
        int right = nums.length;
        int i = 0;
        while(i < right){
            if(nums[i] == 0){
                swap(nums,i++,++left);
                continue;
            }
            if(nums[i] == 1){
                i++;
                continue;
            }
            if(nums[i] == 2){
                swap(nums,i,--right);
                continue;
            }
        }
    }
    public void swap(int[] nums,int i,int j){
        int t = nums[i];
        nums[i] = nums[j];
        nums[j] = t;
    }
}